package com.seeyon.ctp.portal.section;

import com.seeyon.ctp.portal.section.templete.BaseSectionTemplete;
import com.seeyon.ctp.portal.section.templete.BaseSectionTemplete.OPEN_TYPE;
import com.seeyon.ctp.portal.section.templete.HtmlTemplete;
import com.seeyon.ctp.portal.section.templete.HtmlTemplete.ModelType;
import com.seeyon.v3x.rota.domain.TResourceDuty;
import com.seeyon.v3x.rota.manager.RotaManager;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;

public class RotaSection extends BaseSectionImpl
{
  private RotaManager rotaManager;

  public static void main(String[] args)
  {
  }

  public RotaManager getRotaManager()
  {
    return this.rotaManager;
  }

  public void setRotaManager(RotaManager rotaManager) {
    this.rotaManager = rotaManager;
  }

  public String getId()
  {
    return "rotaSection";
  }

  public String getName(Map<String, String> preference)
  {
    String name = (String)preference.get("columnsName");
    if (StringUtils.isBlank(name)) {
      return "值班信息";
    }
    return name;
  }

  public Integer getTotal(Map<String, String> preference)
  {
    return null;
  }

  public String getIcon()
  {
    return null;
  }

  public BaseSectionTemplete projection(Map<String, String> preference)
  {
    HtmlTemplete ht = new HtmlTemplete();
    StringBuilder html = new StringBuilder();
    // 股票信息
    html.append("<SCRIPT type=text/javascript charset=gb2312 src=\"http://hq.sinajs.cn/list=s_sz002129\"></SCRIPT>");
    html.append("<SCRIPT type=text/javascript charset=gb2312 src=\"http://hq.sinajs.cn/list=s_sz002134\"></SCRIPT>");
    html.append("<SCRIPT type=text/javascript charset=gb2312 src=\"http://hq.sinajs.cn/list=s_sh600644\"></SCRIPT>");
    html.append("<SCRIPT type=text/javascript>");
    html.append("var now= new Date();");
    html.append("var elements=hq_str_s_sz002129.split(\",\");");
    html.append("var elements2=hq_str_s_sz002134.split(\",\");");
    html.append("var elements3=hq_str_s_sh600644.split(\",\");</SCRIPT>");
    html.append("<div align=\"center\" style=\"float:left\">");
    html.append("<TABLE><TBODY><TR>");
    html.append("<TH style=\"font-weight:normal; \" width=\"50%\">上市公司</TH>");
    html.append("<TD>&nbsp;&nbsp;价格</TD><TD>&nbsp;涨跌</TD></TR>");
    html.append("<TR><TH style=\"font-weight:normal; \" width=\"50%\"><A href=\"http://stockdata.stock.hexun.com/002129.shtml\" target=_blank>&nbsp;中环股份(002129.SZ)</A></TH>");
    html.append("<TD style=\"font-weight:bold; \" ><A href=\"http://stockdata.stock.hexun.com/002129.shtml\" target=_blank>&nbsp");
    html.append("<SCRIPT type=text/javascript>");
    html.append("if(elements[3].substring(0,1)=='-'){");
    html.append("document.write('<font color=\"green\">'+elements[1]+'</font>');");
    html.append("}else{document.write('<font color=\"red\">'+elements[1]+'</font>');}</SCRIPT></A></TD>");
    html.append("<TD style=\"font-weight:bold; \" ><A href=\"http://stockdata.stock.hexun.com/002129.shtml\" target=_blank>");
    html.append("<SCRIPT type=text/javascript>");
    html.append("if(elements[3].substring(0,1)=='-'){");
    html.append("document.write('<font color=\"green\">'+elements[3]+'</font>');");
    html.append("}else{document.write('<font color=\"red\">'+elements[3]+'</font>');}</SCRIPT></A></TD></TR>");
    html.append("<TR><TH style=\"font-weight:normal; \"><A href=\"http://stockdata.stock.hexun.com/002134.shtml\" target=_blank>&nbsp;天津普林(002134.SZ)</A></TH>");
    html.append("<TD style=\"font-weight:bold; \"><A href=\"http://stockdata.stock.hexun.com/002134.shtml\" target=_blank>&nbsp;");
    html.append("<SCRIPT type=text/javascript>");
    html.append("if(elements2[3].substring(0,1)=='-'){");
    html.append("document.write('<font color=\"green\">'+elements2[1]+'</font>');");
    html.append("}else{document.write('<font color=\"red\">'+elements2[1]+'</font>');}</SCRIPT></A></TD>");
    html.append("<TD style=\"font-weight:bold; \"><A href=\"http://stockdata.stock.hexun.com/002134.shtml\" target=_blank>");
    html.append("<SCRIPT type=text/javascript>");
    html.append("if(elements2[3].substring(0,1)=='-'){");
    html.append("document.write('<font color=\"green\">'+elements2[3]+'</font>');");
    html.append("}else{document.write('<font color=\"red\">'+elements2[3]+'</font>');}</SCRIPT></A></TD></TR>");
    html.append("<TR><TH style=\"font-weight:normal; \"><A href=\"http://stockdata.stock.hexun.com/600644.shtml\" target=_blank>&nbsp;乐山电力(600644.SH)</A></TH>");
    html.append("<TD style=\"font-weight:bold; \"><A href=\"http://stockdata.stock.hexun.com/600644.shtml\" target=_blank>&nbsp;");
    html.append("<SCRIPT type=text/javascript>");
    html.append("if(elements3[3].substring(0,1)=='-'){");
    html.append("document.write('<font color=\"green\">'+elements3[1]+'</font>');");
    html.append("}else{document.write('<font color=\"red\">'+elements3[1]+'</font>');}</SCRIPT></A></TD>");
    html.append("<TD style=\"font-weight:bold; \"><A href=\"http://stockdata.stock.hexun.com/600644.shtml\" target=_blank>");
    html.append("<SCRIPT type=text/javascript>");
    html.append("if(elements3[3].substring(0,1)=='-'){");
    html.append("document.write('<font color=\"green\">'+elements3[3]+'</font>');");
    html.append("}else{document.write('<font color=\"red\">'+elements3[3]+'</font>');}</SCRIPT></A></TD></TR></TBODY></TABLE>");
    // 值班信息
    String date = new SimpleDateFormat("yyyy-M-d").format(Calendar.getInstance().getTime());
    List<TResourceDuty> list = this.rotaManager.findByLikeProperty("dutyDate", date);
    
    html.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"86\">");
    html.append("<tr>");
    html.append("<td align=\"center\" width=\"30%\"><a href=\"../../duty/duty.html\" target=\"_black\"><img src=\"../../duty/zb.gif\" /></a></td>");
    html.append("<td width=\"70%\"><a href=\"../../duty/duty.html\" style=\"text-decoration: none;color: #000000;\" target=\"_black\">今日值班:<br/>");
    for (TResourceDuty trd : list)
    {
      html.append(trd.getType() + ":" + trd.getName() + "<br/>");
    }
    html.append("</a>");
    html.append("</td>");
    html.append("</tr>");
    html.append("</table>");
    html.append("</div>");
    // 天气信息
    html.append("<div align=\"center\" style=\"float:right\">");
    html.append("<iframe allowtransparency=\"true\" frameborder=\"0\" width=\"150\" height=\"230\" scrolling=\"no\" src=\"http://tianqi.2345.com/plugin/widget/index.htm?s=2&z=1&t=0&v=1&d=1&bd=0&k=&f=&q=1&e=1&a=1&c=54511&w=140&h=128&align=center\"></iframe>");
    html.append("</div>");
    
    ht.setHeight("230");
    ht.setHtml(html.toString());
    ht.setModel(HtmlTemplete.ModelType.inner);
    ht.setShowBottomButton(true);
    ht.addBottomButton("common_more_label", "/duty/calendar.html", 
      BaseSectionTemplete.OPEN_TYPE.href_blank.name());

    return ht;
  }
}